home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Pict2Ascii 1.03 / Panes / LDynamicPopupMenu / LDynamicPopupMenu.cp next >
Encoding:
Text File  |  1997-05-21  |  4.5 KB  |  141 lines  |  [TEXT/CWIE]

  1. // LDynamicPopupMenu.cp
  2. //        written by Constantine Spathis
  3. //        see LDynamicPopupMenu.h for more info
  4. //
  5. //        1/8/95        CS    Initial Iteration
  6. //         97/05/20    P. Lamboley. See LDynamicPopupMenu.h
  7. //
  8.  
  9. #include "LDynamicPopupMenu.h"
  10. #include "LString.h"
  11.  
  12.  
  13. // class variables
  14. Int16    LDynamicPopupMenu::mTitleWidth    = 0;
  15. Int16    LDynamicPopupMenu::mTitleJust    = popupTitleRightJust;
  16. Int16    LDynamicPopupMenu::mMenuID        = first_menu_ID;
  17.  
  18.  
  19. // ---------------------------------------------------------------------------------
  20. //        • LDynamicPopupMenu (LStream*)
  21. // ---------------------------------------------------------------------------------
  22. LDynamicPopupMenu::LDynamicPopupMenu (LStream* inStream)
  23.     : LStdPopupMenu(inStream)
  24. { }
  25.  
  26.  
  27. // ---------------------------------------------------------------------------------
  28. //        • CreateLDynamicPopupMenuStream (LStream*) [static]
  29. // ---------------------------------------------------------------------------------
  30. LDynamicPopupMenu*
  31. LDynamicPopupMenu::CreateLDynamicPopupMenuStream (LStream *inStream)
  32. {    
  33.     // Create a "normal" LStdPopup
  34.     LDynamicPopupMenu *thePopup = new LDynamicPopupMenu (inStream);
  35.     
  36.     // Get old control title
  37.     Str255    theTitle;
  38.     LString::CopyPStr ( (**(thePopup->mMacControlH)).contrlTitle, theTitle);
  39.  
  40.     // Get old control Refcon
  41.     long theRefCon = ::GetControlReference (thePopup->mMacControlH);
  42.  
  43.     // Get old control initial value
  44.     Int32 theValue = thePopup->GetValue();
  45.     
  46.     // Get a copy of the menu, or a new one if the popup uses a resource list
  47.     MenuHandle theMenu = thePopup->GetMacMenuH();
  48.     if ( theRefCon == 0 || theRefCon == '????' )
  49.         ::HandToHand ( (Handle*)&theMenu );
  50.     else
  51. //        theMenu = ::NewMenu (mMenuID, (**thePopup->mMacControlH).contrlTitle);
  52.         theMenu = ::NewMenu (mMenuID, theTitle);
  53.  
  54.     //    Here you really should add some code to check that menu was properly made
  55.     //    because HandToHand and NewMenu can fail. Just a suggestion :-)
  56.     //    xassert(ValidHandle(Handle(theMenu)));
  57.  
  58.     // Dispose of the control PowerPlant made
  59.     ::DisposeControl(thePopup->mMacControlH);
  60.  
  61.     // The copy is for this control exclusive use
  62.     (**theMenu).menuID  = mMenuID;
  63.  
  64.     // make it hierarchical as needed for a popup
  65.     ::InsertMenu (theMenu, ::hierMenu);
  66.     
  67.     // mMinValue holds the MenuID of the menu to link the control to.
  68.     thePopup->mMinValue = mMenuID;
  69.  
  70.     // mValue holds the title justification : no way to retrieve it from the PPob
  71.     thePopup->mValue = mTitleJust;
  72.  
  73.     // mMaxValue holds the title width : no way to retrieve it from the PPob
  74.     if ( mTitleWidth < 0 )
  75.         thePopup->mMaxValue = 4+StringWidth(theTitle);
  76.     else
  77.         thePopup->mMaxValue = mTitleWidth;
  78.                                                     
  79.     // And make our own Control using PowerPlants StdControl maker
  80.     thePopup->InitStdControl (thePopup->mControlKind, thePopup->mTextTraitsID, theTitle, theRefCon);
  81.  
  82.     /* ****** Plagirism On ******* */
  83.  
  84.     // See LStdPopupMenu::InitStdPopupMenu (which is private...)
  85.     thePopup->mValue    = ::GetControlValue  (thePopup->mMacControlH);
  86.     thePopup->mMinValue = ::GetControlMinimum(thePopup->mMacControlH);
  87.     thePopup->mMaxValue = ::GetControlMaximum(thePopup->mMacControlH);    
  88.  
  89.     // What use ?
  90.     if (0 != thePopup->mValue) {
  91.         ::SetControlValue (thePopup->mMacControlH, 0);
  92.         thePopup->mValue = ::GetControlValue(thePopup->mMacControlH);
  93.     }
  94.  
  95.     /* ****** Plagirism Off ******* */
  96.  
  97.     // Increment generated Menu ID
  98.     mMenuID++;
  99.  
  100.     // Apply min and max and set the initial value (users can forget
  101.     // FinishedCreatingMenu if they don't change the count of items)
  102.     thePopup->FinishedCreatingMenu (theValue);
  103.  
  104.     return thePopup;
  105. }
  106.  
  107.  
  108. // ---------------------------------------------------------------------------------
  109. //        • FinishedCreatingMenu (Int32)
  110. // ---------------------------------------------------------------------------------
  111. void LDynamicPopupMenu::FinishedCreatingMenu (Int32 initialItem)
  112. {
  113.     mMinValue = 1;
  114.     mMaxValue = ::CountMItems ( GetMacMenuH() );
  115.     SetStdMinAndMax();
  116.     SetValue (initialItem);
  117. }
  118.  
  119.  
  120. // ---------------------------------------------------------------------------------
  121. //        • SetTitleWidth (Int16)
  122. // ---------------------------------------------------------------------------------
  123. void LDynamicPopupMenu::SetTitleWidth (Int16 inWidth)
  124. {
  125.     mTitleWidth = inWidth;
  126. }
  127.  
  128.  
  129. // ---------------------------------------------------------------------------------
  130. //        • SetTitleJust (Int16)
  131. // ---------------------------------------------------------------------------------
  132. void LDynamicPopupMenu::SetTitleJust (Int16 inJust)
  133. {
  134.     mTitleJust = inJust;
  135.     if (inJust != popupTitleLeftJust
  136.     &&    inJust != popupTitleCenterJust
  137.     &&    inJust != popupTitleRightJust    )
  138.         mTitleJust = popupTitleRightJust;
  139. }
  140.  
  141.